<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="qldc.pm.tiensu.constants.TrangThaiTrichLucEnum"%>
<%@page import="com.liferay.portal.kernel.language.LanguageUtil"%>
<%@page import="qldc.pm.tiensu.searchcontainer.YeuCauTrichLucSearchTerms"%>
<%@page import="qldc.pm.tiensu.searchcontainer.YeuCauTrichLucDisplayTerms"%>
<%@page import="qldc.pm.tiensu.searchcontainer.YeuCauTrichLucSearch"%>
<%@page import="qldc.pm.tiensu.service.YeuCauTrichLucLocalServiceUtil"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@page import="qldc.pm.qtht.dmdc.service.TinhLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.Tinh"%>
<%@page import="java.util.List"%>
<%@include file="../../init.jsp"%>

<%
SimpleDateFormat format = new SimpleDateFormat(TienSuConstants.DATE_PATTERN);
String pathThemeImages = themeDisplay.getPathThemeImages();

PortletURL portletURL = renderResponse.createRenderURL();
portletURL.setParameter("mvcPath", "/html/view.jsp");
portletURL.setParameter("chonChucNangItem", TienSuConstants.QUAN_LY_YEU_CAU_TRICH_LUC);
%>

<portlet:renderURL var="themMoiYeuCauTrichLucTienSu">
	<portlet:param name="mvcPath" value="/html/view.jsp"/>
	<portlet:param name="chonChucNangItem" value="<%=TienSuConstants.QUAN_LY_YEU_CAU_TRICH_LUC %>"/>
	<portlet:param name="tabs1" value="cap_nhat_yeu_cau_trich_luc"/>
	<portlet:param name="redirect" value="<%=portletURL.toString() %>"/>
	<portlet:param name="mode" value="add"/>
</portlet:renderURL>

<form action="<%=portletURL.toString() %>" method="POST" name="<portlet:namespace />fm">

	<%
	YeuCauTrichLucSearch yeuCauTrichLucSearch = new YeuCauTrichLucSearch(renderRequest, portletURL);
	YeuCauTrichLucDisplayTerms displayTerms = (YeuCauTrichLucDisplayTerms) yeuCauTrichLucSearch.getDisplayTerms();
	YeuCauTrichLucSearchTerms searchTerms = (YeuCauTrichLucSearchTerms) yeuCauTrichLucSearch.getSearchTerms();
	%>
	
	<table class="global-Search">
		<tr>
			<td class="aui-w20"><liferay-ui:message key="so-dinh-danh-ca-nhan" /></td>
			<td class="aui-w30"><input type="text" name="<portlet:namespace/>soDinhDanhCaNhanDoiTuongTrichLuc" value="<%=searchTerms.getSoDinhDanhCaNhanDoiTuongTrichLuc() %>" /></td>
			<td class="aui-w20"><liferay-ui:message key="so-cmnd" /></td>
			<td class="aui-w30"><input type="text" name="<portlet:namespace/>soCMNDDoiTuongTrichLuc" value="<%=searchTerms.getSoCMNDDoiTuongTrichLuc() %>" /></td>
		</tr>

		<tr>
			<td><liferay-ui:message key="ho-va-ten" /></td>
			<td><input type="text" name="<portlet:namespace/>hoVaTenDoiTuongTrichLuc" value="<%=searchTerms.getHoVaTenDoiTuongTrichLuc() %>" /></td>
			<td><liferay-ui:message key="trang-thai" /></td>
			<td>
				<%
				TrangThaiTrichLucEnum [] trangThais = TrangThaiTrichLucEnum.values(); 
				%>
				<select id="<portlet:namespace/>trangThaiTrichLuc" name="<portlet:namespace/>trangThaiTrichLuc" >
				<%
				for(int i = 0; i <trangThais.length; i++) {
				%>
					<option value=<%=trangThais[i].getValue() %> <%= (trangThais[i].getValue() == searchTerms.getTrangThaiTrichLuc()) ? "selected=selected" : "" %>><liferay-ui:message key="<%=trangThais[i].getKey() %>" /></option>
				<%
				}
				%>
				</select>
			</td>
		</tr>
		
		<tr>
			<td><liferay-ui:message key="ho-va-ten-nguoi-yeu-cau-trich-luc" /></td>
			<td><input type="text" name="<portlet:namespace/>hoVaTenNguoiYeuCauTrichLuc" value="<%=searchTerms.getHoVaTenNguoiYeuCauTrichLuc() %>" /></td>
			<td><liferay-ui:message key="co-quan-nguoi-yeu-cau-trich-luc" /></td>
			<td><input type="text" name="<portlet:namespace/>coQuanNguoiYeuCauTrichLuc" value="<%=searchTerms.getCoQuanNguoiYeuCauTrichLuc() %>" /></td>
		</tr>
		
		<tr>
			<td><liferay-ui:message key="ngay-lap-trich-luc-tu" /></td>
			<td class="ip-datepicker">
				<input class="datepicker" type="text" style="width: 90%;" id="<portlet:namespace/>tuNgayTaoTrichLuc"  value="<%=Validator.isNotNull(searchTerms.getTuNgayTaoTrichLuc())? format.format(searchTerms.getTuNgayTaoTrichLuc()):"" %>" name="<portlet:namespace/>tuNgayTaoTrichLuc" />
			</td>
			
			<td><liferay-ui:message key="den-ngay" /></td>
			<td class="ip-datepicker">
				<input class="datepicker" style="width: 90%;" value="<%=Validator.isNotNull(searchTerms.getDenNgayTaoTrichLuc())? format.format(searchTerms.getDenNgayTaoTrichLuc()):"" %>"  type="text" id="<portlet:namespace/>denNgayTaoTrichLuc" name="<portlet:namespace/>denNgayTaoTrichLuc" />
			</td>
		</tr>
		
		
		<tr>
			<td></td>
			<td colspan="3">
				<div align="left">
					<input type="button"  onclick="<portlet:namespace/>searchValidate()"  class="btn btn-primary" value="<liferay-ui:message key="tim" />" />
					<input type="button" class="btn btn-danger" onclick="javascript:submitForm(document.hrefFm,'<%= themMoiYeuCauTrichLucTienSu.toString() %>');" value="<liferay-ui:message key="them-yeu-cau-trich-luc" />" />
				</div>
			</td>
		</tr>	
	</table>
</form>

<liferay-ui:search-container searchContainer="<%=yeuCauTrichLucSearch %>">
	<liferay-ui:search-container-results>		
		<%
			results = YeuCauTrichLucLocalServiceUtil
							.findBySDDCN_NYCTL_CQ_CMND_DTTL_SHK_ThoiGian(searchTerms.getTrangThaiTrichLuc(),
									searchTerms.getSoDinhDanhCaNhanDoiTuongTrichLuc(),
									searchTerms.getHoVaTenNguoiYeuCauTrichLuc(),
									searchTerms.getCoQuanNguoiYeuCauTrichLuc(),
									searchTerms.getSoCMNDDoiTuongTrichLuc(),
									searchTerms.getHoVaTenDoiTuongTrichLuc(),
									
									searchTerms.getSoSoHoKhauDoiTuongTrichLuc(),searchTerms.getTuNgayTaoTrichLuc(),searchTerms.getDenNgayTaoTrichLuc(),
									yeuCauTrichLucSearch.getStart(), yeuCauTrichLucSearch.getEnd(), 
									yeuCauTrichLucSearch.getOrderByComparator());
				
			total = YeuCauTrichLucLocalServiceUtil.countBySDDCN_NYCTL_CQ_CMND_DTTL_SHK_ThoiGian
					(searchTerms.getTrangThaiTrichLuc(),
					searchTerms.getSoDinhDanhCaNhanDoiTuongTrichLuc(),
					searchTerms.getHoVaTenNguoiYeuCauTrichLuc(),
					searchTerms.getCoQuanNguoiYeuCauTrichLuc(),
					searchTerms.getSoCMNDDoiTuongTrichLuc(),
					searchTerms.getHoVaTenDoiTuongTrichLuc(),
					searchTerms.getSoDinhDanhCaNhanDoiTuongTrichLuc(),searchTerms.getTuNgayTaoTrichLuc(),searchTerms.getDenNgayTaoTrichLuc());
			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
		%>
	</liferay-ui:search-container-results>
	<%
	int start = yeuCauTrichLucSearch.getDelta() * (yeuCauTrichLucSearch.getCur() - 1);
	%>
	<liferay-ui:search-container-row className="qldc.pm.tiensu.model.YeuCauTrichLuc" keyProperty="yeuCauTrichLucId" modelVar="yeuCauTrichLuc" >
		<liferay-ui:search-container-column-text cssClass="aui-w3 txt-center" name='stt' value="<%=String.valueOf(++start) %>" />
		<liferay-ui:search-container-column-text name='so-dinh-danh-ca-nhan' property="soDinhDanhCaNhanDoiTuongTrichLuc" orderable="<%=true %>" orderableProperty="soDinhDanhCaNhanDoiTuongTrichLuc"/>
		<liferay-ui:search-container-column-text name='so-cmnd' property="soCMNDDoiTuongTrichLuc" orderable="<%=true %>" orderableProperty="soCMNDDoiTuongTrichLuc"/>
		<liferay-ui:search-container-column-text name='ho-va-ten' property="hoVaTenDoiTuongTrichLuc" orderable="<%=true %>" orderableProperty="hoVaTenDoiTuongTrichLuc"/>
		<liferay-ui:search-container-column-text name='ma-yeu-cau-trich-luc' property="maYeuCauTrichLuc" orderable="<%=true %>" orderableProperty="maYeuCauTrichLuc"/>
		<liferay-ui:search-container-column-text name='co-quan-nguoi-yeu-cau-trich-luc' property="coQuanYeuCauTrichLuc" orderable="<%=true %>" orderableProperty="coQuanYeuCauTrichLuc"/>
		<liferay-ui:search-container-column-text name='ngay-lap-trich-luc'  orderable="<%=true %>" orderableProperty="createDate">
			<%=Validator.isNotNull(yeuCauTrichLuc.getCreateDate()) ? format.format(yeuCauTrichLuc.getCreateDate()) :"" %>
		</liferay-ui:search-container-column-text>
		
		<%
		String trangThai = yeuCauTrichLuc.getDaTrichLuc() ? TrangThaiTrichLucEnum.DA_TRICH_LUC.getKey(): TrangThaiTrichLucEnum.CHUA_TRICH_LUC.getKey();
		%>
		<liferay-ui:search-container-column-text name='<%=LanguageUtil.get(request.getLocale(), "trang-thai")%>' > <liferay-ui:message key="<%=trangThai %>" /> </liferay-ui:search-container-column-text>

		<liferay-ui:search-container-column-jsp cssClass="aui-Action txt-center" path="/html/tiensu/trich_luc_tien_su/actions.jsp" align="right" />
	</liferay-ui:search-container-row>
	<liferay-ui:search-iterator searchContainer="<%=yeuCauTrichLucSearch %>" />

</liferay-ui:search-container>
<script>


$(function() {	 
	$("#<portlet:namespace/>tuNgayTaoTrichLuc").datepicker({
		showOn: "both",
		buttonImage: "<%=pathThemeImages%>/common/calendar.png",
			buttonImageOnly : true,
			buttonText : "<liferay-ui:message key="tuNgayTaoTrichLuc" />",
			dateFormat : "dd/mm/yy",
			onClose: function( selectedDate ) {
				 $("#<portlet:namespace/>denNgayTaoTrichLuc").datepicker( "option", "minDate", selectedDate );
				 }
		});
	$("#<portlet:namespace/>denNgayTaoTrichLuc").datepicker({
		showOn: "both",
		buttonImage: "<%=pathThemeImages%>/common/calendar.png",
			buttonImageOnly : true,
			buttonText : "<liferay-ui:message key="denNgayTaoTrichLuc" />",
			dateFormat : "dd/mm/yy",
			onClose: function( selectedDate ) {
				 $("#<portlet:namespace/>tuNgayTaoTrichLuc").datepicker( "option", "maxDate", selectedDate );
				 }
		});

	
});
function <portlet:namespace/>searchValidate(){
	var soCMND = $('#<portlet:namespace/>soCMND');
	if(soCMND.val() != '' && !validateIntegerWithLength(soCMND.val(),1,12)) {
		showPopupConfirm('<liferay-ui:message key="so-cmnd-nay-khong-hop-le" />',['Ok'],function(index){
			soCMND.focus();
		});
		return false;
	}else{
		document.<portlet:namespace />fm.submit();
	}
}
</script>